//
//  SandTableCell.m
//  宜居HD
//
//  Created by 陈柏兵 on 16/5/5.
//  Copyright © 2016年 张金国. All rights reserved.
//

#import "SandTableCell.h"
#import "Macro.h"
#import "Masonry.h"

@interface SandTableCell ()


@end

@implementation SandTableCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        
        [self MyContainer];
        
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (void)handleDelatrAction:(UIButton *)sender {
    if (self.isShowBtn == NO) {
        self.delateAction();
    }
}


- (void)MyContainer {
    [self.CellView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(TenOffsetViewMargin);
        make.left.equalTo(self.mas_left);
        make.right.equalTo(self.mas_right);
        make.height.equalTo(@(SCREEN_HEIGHT*0.07));
    }];
    
//    [self.TitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(_CellView.mas_top);
//        make.left.equalTo(_CellView.mas_left).offset(10);
//        make.width.equalTo(_CellView.mas_width).multipliedBy(2/3);
//        make.height.equalTo(_CellView.mas_height);
//    }];
    
    [self.delateBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_CellView.mas_centerY);
        make.right.equalTo(_CellView.mas_right).offset(-FiveOffsetViewMargin);
        make.width.height.mas_equalTo(30);
    }];
}

- (UIView *)CellView {
    if (_CellView == nil) {
        //背景view
        _CellView = [[UIView alloc] init];
        _CellView.backgroundColor = [UIColor whiteColor];
        _CellView.userInteractionEnabled = YES;
        _CellView.layer.cornerRadius = 5;
        [self.contentView addSubview:_CellView];
    }
    return _CellView;
}

- (UILabel *)TitleLabel {
    if (_TitleLabel == nil) {
        _TitleLabel = [[UILabel alloc] init];
        _TitleLabel.backgroundColor = [UIColor redColor];
        [_CellView addSubview:_TitleLabel];
    }
    return _TitleLabel;
}

- (UIButton *)delateBtn {
    if (_delateBtn == nil) {
        _delateBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_delateBtn setImage:[UIImage imageNamed:@"MoreDetails_Do"] forState:0];
        [_delateBtn addTarget:self action:@selector(handleDelatrAction:) forControlEvents:UIControlEventTouchUpInside];
        [_CellView addSubview:_delateBtn];
    }
    return _delateBtn;
}

- (void)setIsShowBtn:(BOOL)isShowBtn {
    _isShowBtn = isShowBtn;
    if (isShowBtn == YES) {
        [_delateBtn setImage:[UIImage imageNamed:@"MoreDetails"] forState:0];
    } else {
        [_delateBtn setImage:[UIImage imageNamed:@"MoreDetails_Do"] forState:0];
    }
}


@end
